from haystack import indexes

from goods.models import SKU


class SKUIndex(indexes.SearchIndex, indexes.Indexable):

    # document参数为指定当前字段为索引字段, use_template参数为指定字段是什么
    text = indexes.CharField(document=True, use_template=True)

    def get_model(self):

        return SKU

    # 索引建立时对数据进行清洗
    def index_queryset(self, using=None):

        return self.get_model().objects.filter(is_launched=True)

